package com.x.Part1_static;

/**
 * ClassName: CircleTest
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.03.01 17:26
 */

class Circle{
    private double radius;
    private int id;

    private static int total ;//创建的实例对象的个数，采用静态变量
    private static int init  = 1001;//初始id为1001

    public Circle(){
        //每次创建对象时，id自动赋值
        this.id = init++;

        //每次创建对象时，total自动加一
        total++;
    }

    public Circle(double radius){
        this();
        this.radius=radius;
    }


    //static的get方法获取total值
    public static int getTotal() {
        return total;
    }

    @Override
    public String toString() {
        return "Circle{" + "radius=" + radius + ", id=" + id + '}';
    }
}
public class CircleTest {
    public static void main(String[] args) {

        Circle c1 = new Circle();
        Circle c2 = new Circle(2);
        Circle c3 = new Circle(4);
        Circle c4 = new Circle();

        System.out.println(c1.toString());
        System.out.println(c2.toString());
        System.out.println(c3.toString());
        System.out.println(c4.toString());

        System.out.println(Circle.getTotal());

    }
}
